﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using NCI.EasyObjects;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using CMS.BLL.Entity;
using CMS.DAL;


namespace CMS.BLL
{
    public class TourCategory
    {
        #region Common
        public eTourCategory Data;

        public TourCategory()
        {
            Data = new eTourCategory();
		}

        ~TourCategory()
        {
		}

		public virtual void Dispose()
        {
		}

        public int DeleteById(int ID)
        {
            int nResult = 0;
           cTourCategory objDAL = new cTourCategory();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.MarkAsDeleted();
                objDAL.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        public void LoadById(int ID)
        {
           cTourCategory objDAL = new cTourCategory();
            objDAL.LoadByPrimaryKey(ID);
            ConvertData(objDAL);
        }

        public int Insert()
        {
            int nResult = 0;
           cTourCategory objInfor = new cTourCategory(); 
            try
            {
                objInfor.AddNew();
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = objInfor.TourCategoryID;
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

        public int Update(int ID)
        {
            int nResult = 0;
           cTourCategory objInfor = new cTourCategory();
            try
            {
                objInfor.LoadByPrimaryKey(ID);
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = ID; 
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

        private void MappingData(cTourCategory objInfor)
        {

            objInfor.TourCategoryName3 = Data.TourCategoryName3;
            objInfor.TourCategoryName1 = Data.TourCategoryName1;
            objInfor.TourCategoryName2 = Data.TourCategoryName2;
            objInfor.Parents = Data.Parents;
            objInfor.Parents = Data.Parents;
            objInfor.Images = Data.Images;
            objInfor.RegionID = Data.RegionID;
            objInfor.TourCategoryDetail1 = Data.TourCategoryDetail1;
            objInfor.TourCategoryDetail2 = Data.TourCategoryDetail2;
            objInfor.TourCategoryDetail3 = Data.TourCategoryDetail3;
        }

        private void ConvertData(cTourCategory objInfor)
        {
            try { Data.TourCategoryName3 = objInfor.TourCategoryName3; }
            catch { Data.TourCategoryName3 = ""; }
            try { Data.TourCategoryName1 = objInfor.TourCategoryName1; }
            catch { Data.TourCategoryName1 = ""; }
            try { Data.TourCategoryName2 = objInfor.TourCategoryName2; }
            catch { Data.TourCategoryName2 = ""; }
            Data.Parents = objInfor.Parents;
            Data.Images = objInfor.Images;
            Data.RegionID = objInfor.RegionID;
            Data.TourCategoryDetail1 = objInfor.TourCategoryDetail1;
            Data.TourCategoryDetail2 = objInfor.TourCategoryDetail2;
            Data.TourCategoryDetail3 = objInfor.TourCategoryDetail3;
        }
       
        #endregion

        
        public DataTable SearchByParent(int Parent)
        {
            DataTable tbResult = new DataTable();
            cTourCategory objDAL = new cTourCategory();
            tbResult = objDAL.SearchByParent(Parent);
            return tbResult;
        }
        public DataTable Search(int RegionID, int CountryID)
        {
            DataTable tbResult = new DataTable();
            cTourCategory objDAL = new cTourCategory();
            tbResult = objDAL.Search(RegionID, CountryID);
            return tbResult;
        }
        public DataTable GetALL()
        {
            DataTable tbResult = new DataTable();
            cTourCategory objDAL = new cTourCategory();
            tbResult = objDAL.GetALL();
            return tbResult;
        }
    }
}
